package com.ch999.detect.View.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ch999.detect.R;
import com.ch999.detect.mode.bean.PhoneGoodsMode;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13 0013.
 */

public class PhoneNameAdatper extends RecyclerView.Adapter<PhoneNameAdatper.ViewHolder> {
    public Context mContext;
    public List<PhoneGoodsMode.DataBean> data;

    public PhoneNameAdatper(Context context, List<PhoneGoodsMode.DataBean> data) {
        this.mContext = context;
        this.data = data;
    }

    public interface OnClickItemListener {
        void onClickItemListener(int posation);
    }

    OnClickItemListener onClickItemListener;

    public void setOnClickItemListener(OnClickItemListener onClickItemListener) {
        this.onClickItemListener = onClickItemListener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_phone_jixin_layout, parent, false));
        return holder;
    }

    @Override
    public int getItemCount() {
        if (data == null) {
            return 0;
        }
        return data.size();
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        PhoneGoodsMode.DataBean datBean = data.get(position);
        holder.tvName.setText(datBean.getBrandName());

        if (datBean.isSeleced()){
            holder.line.setVisibility(View.VISIBLE);
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.es_g));
        }else {
            holder.line.setVisibility(View.GONE);
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.es_b));
        }

        holder.llRootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onClickItemListener != null) {
                    onClickItemListener.onClickItemListener(position);
                }
            }
        });
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        FrameLayout llRootView;
        View line ;

        ViewHolder(View view) {
            super(view);
            tvName = (TextView)view.findViewById(R.id.tv_name);
            llRootView = (FrameLayout) view.findViewById(R.id.ll_root_view);
            line =  view.findViewById(R.id.view_line);
        }
    }
}
